<?php

header("Content-Type: text/html;charset=utf-8");
class TestPush{

    function sign($arr) {
        ksort($arr);
        $str = array();
        foreach($arr as $key => $val){
            $str[] = "{$key}={$val}";
        }
        $str = implode('&',$str);
        return md5($str);
    }

    function post_get($url,$param = null,$decode = true) {
        $option = array(
            'http' => array(
                'method'        => 'POST',
                'ignore_errors' => true,
                'header' => "Content-type: application/x-www-form-urlencoded",
            ),
        );
        if ($param) {
            $option['http']['content'] = http_build_query($param);
        }
        $context = stream_context_create($option);

        // Send the request
        $response = file_get_contents($url, false, $context);
//        $response = str_replace(':}', ':""}', $response);
//        $response = str_replace(':,', ':"",', $response);


        if (!$decode) {
            return $response;
        }

        return json_decode($response,true);

    }

    function test(){
        $data = array(
            'buyerName' => 'bin',                  //在厂家网的下单买家姓名
            'buyerMobile' => '18703736134',        //买家手机号码
            'orderSn' => '0152223344',               //买家在厂家网下单后的订单编号，不能重复使用
            'payAmount' => 100,                    //买家在厂家网下单后的实际支付金额
            'payType' => 'test',                   //支付宝、微信支付(wxpay)、在线支付
			'payTime'=>Time(),                     //买家在厂家网下单时间,这里去推送时间，请填写实际时间
            'paySn' => '1234567',                  //电子支付单号，一般来说28位数字
            'consignee' => 'bin',                  //收件人
            'idNumber' => '410703199103263035',    //收件人身份证号码    
            'address' => 'HeNan XinXiang Test',    //收件人地址
            'provinceCode' => '110000',            //收件人省份（直辖市）代码
            'cityCode' => '110000',                //收件人地级市（直辖市）代码
            'areaCode' => '110101',                //收件人区县代码
            'consigneeMobile' => '18703736134',    //收件人手机号码
            'orderGoods' => json_encode(array(
                array(
                    'goodsId' => '314',        //商品id，媄妍网
                    'num' => 1,                //这这张订单中商品数量
                    'price' => 20              //厂家网商品销售价格
                ),
				array(
				    'goodsId' => '317',
					'num' => 2,
					'price' => 15
				),
				array(
				     'goodsId'=>'316',
					 'num'=>3,
					 'price'=>30
				)
				
            )),
            'userName' => 'llyb120',          //厂家网在媄妍商城的用户名称
            'userPass' => md5(123456),        //密码
        );
        $data['sign'] = $this->sign($data);


        $url = "http://www.beeasy.com.cn/shop/?act=convert_order";        //推送地址

        $res = $this->post_get($url,$data);
        if ($res['errCode'] == 0) {
            echo "推送成功";
        }
        else{
            echo "推送失败，错误代码为 {$res['errCode']},错误信息为 {$res['errMessage']}";
        }
//        print_r($res);
    }
}

$ins = new TestPush();
$ins->test();